package com.gwt.mvp.sample.client.view;

import com.google.gwt.event.dom.client.HasClickHandlers;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.DecoratorPanel;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;
import com.gwt.mvp.sample.client.presenter.EntityPresenter;

public class EntityView extends Composite implements EntityPresenter.Display{

	private final Label contentLabel;
	private final Button incrementButton;
	private final Button resetViewButton;
	
	public EntityView(){
		
		contentLabel 	= new Label("0");
		incrementButton = new Button("Increment value");
		resetViewButton = new Button("Reset View");
		
		DecoratorPanel contentDecorator = new DecoratorPanel();
		
		HorizontalPanel labelPanel = new HorizontalPanel();
		labelPanel.setSpacing(5);
		labelPanel.add(new Label("Value: "));
		labelPanel.add(contentLabel);
		
		HorizontalPanel buttonsPanel = new HorizontalPanel();
		buttonsPanel.setSpacing(5);
		buttonsPanel.add(incrementButton);
		buttonsPanel.add(resetViewButton);
		
		VerticalPanel panel = new VerticalPanel();
		panel.setSpacing(10);
		panel.add(labelPanel);
		panel.add(buttonsPanel);
		
		contentDecorator.add(panel);
		
		initWidget(contentDecorator);
	
	}
	
	@Override
	public HasClickHandlers getIncrementButton() {
		return incrementButton;
	}

	@Override
	public HasClickHandlers getResetViewButton() {
		return resetViewButton;
	}

	@Override
	public void setData(Integer data) {
		contentLabel.setText(String.valueOf(data));
	}

	public Widget asWidget() {
		return this;
	}

}
